package translated;

import java.util.List;
import edu.pku.sei.modeler.jet.model.*;
import edu.pku.sei.modeler.model.core.*;
import edu.pku.sei.modeler.jet.util.*;

public class PaletteFactoryGen
{
  protected static String nl;
  public static synchronized PaletteFactoryGen create(String lineSeparator)
  {
    nl = lineSeparator;
    PaletteFactoryGen result = new PaletteFactoryGen();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "/**" + NL + " * Copyright (c) Software Institute of PKU" + NL + " * All rights reserved. " + NL + " * This program and the accompanying materials" + NL + " * are made available under the terms of the Eclipse Public License v1.0" + NL + " * which accompanies this distribution, and is available at" + NL + " * http://www.eclipse.org/legal/epl-v10.html" + NL + " *" + NL + " */" + NL + "package ";
  protected final String TEXT_2 = ";" + NL + "" + NL + "import edu.pku.sei.modeler.images.ImageProvider;" + NL + "import edu.pku.sei.modeler.model.core.MetaModel;" + NL + "import edu.pku.sei.modeler.ui.palette.DiagramPaletteFactory;" + NL + "import edu.pku.sei.modeler.ui.palette.EntryDescriptor;" + NL + "import ";
  protected final String TEXT_3 = ";" + NL + "" + NL + "/**" + NL + " * @generated" + NL + " *" + NL + " */" + NL + "public class ";
  protected final String TEXT_4 = " extends DiagramPaletteFactory {" + NL + "\tprivate static ";
  protected final String TEXT_5 = " pFactory;" + NL + "\tprivate ";
  protected final String TEXT_6 = "(MetaModel model) {" + NL + "\t\tsuper(model);" + NL + "\t}" + NL + "\t" + NL + "\tpublic static ";
  protected final String TEXT_7 = " getDefault(MetaModel model) {\t" + NL + "\t\tDiagramPaletteFactory pFactory = model2factory.get(model);" + NL + "\t\tif(pFactory == null) {" + NL + "\t\t\tpFactory = new ";
  protected final String TEXT_8 = "(model);" + NL + "\t\t\t// config the factory" + NL + "\t\t\tEntryDescriptor entry;" + NL + "\t\t\t";
  protected final String TEXT_9 = NL + "\t\t\tentry = new EntryDescriptor();" + NL + "\t\t\tentry.diagramType = \"";
  protected final String TEXT_10 = "\";" + NL + "\t\t\tentry.elementType = ";
  protected final String TEXT_11 = ";" + NL + "\t\t\tentry.isNode = ";
  protected final String TEXT_12 = ";" + NL + "\t\t\tentry.label = \"";
  protected final String TEXT_13 = "\";" + NL + "\t\t\tentry.shortDesc = \"Crate a ";
  protected final String TEXT_14 = "\";" + NL + "\t\t\tentry.iconSmall = ImageProvider.getImageDescriptor(ImageProvider.";
  protected final String TEXT_15 = ");" + NL + "\t\t\tpFactory.addEntry(entry);" + NL + "\t\t\t";
  protected final String TEXT_16 = NL + "\t\t\t" + NL + "\t\t\tmodel2factory.put(model, pFactory);" + NL + "\t\t}" + NL + "\t\treturn (";
  protected final String TEXT_17 = ")pFactory;" + NL + "\t}" + NL + "}";
  protected final String TEXT_18 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
     List infoList = (List) argument; 
    stringBuffer.append(TEXT_1);
    stringBuffer.append(ModelerConstants.pkgBase + "." + ModelerConstants.internalBase);
    stringBuffer.append(TEXT_2);
    stringBuffer.append(ModelerConstants.pkgBase + "." + ModelerConstants.modelBase + "." + ModelerConstants.modelPackage);
    stringBuffer.append(TEXT_3);
    stringBuffer.append(ModelerConstants.paletteFactory);
    stringBuffer.append(TEXT_4);
    stringBuffer.append(ModelerConstants.paletteFactory);
    stringBuffer.append(TEXT_5);
    stringBuffer.append(ModelerConstants.paletteFactory);
    stringBuffer.append(TEXT_6);
    stringBuffer.append(ModelerConstants.paletteFactory);
    stringBuffer.append(TEXT_7);
    stringBuffer.append(ModelerConstants.paletteFactory);
    stringBuffer.append(TEXT_8);
    
			for(int i=0; i<infoList.size(); i++) {
				DiagramInfo info = (DiagramInfo)infoList.get(i);
				String type = info.getType();
				List<MetaClass> clsList = info.getClsList();
				for(MetaClass cls:clsList) {
					boolean isNode = true;
					String iconStr = "DEFAULT_BLOCK";
					if(cls instanceof MetaRelationship) {
						isNode = false;
						iconStr = "DEFAULT_LINK";
					}
			
    stringBuffer.append(TEXT_9);
    stringBuffer.append(type);
    stringBuffer.append(TEXT_10);
    stringBuffer.append(PackageRetriever.retrieveClassID(cls));
    stringBuffer.append(TEXT_11);
    stringBuffer.append(isNode);
    stringBuffer.append(TEXT_12);
    stringBuffer.append(cls.getName());
    stringBuffer.append(TEXT_13);
    stringBuffer.append(cls.getName());
    stringBuffer.append(TEXT_14);
    stringBuffer.append(iconStr);
    stringBuffer.append(TEXT_15);
    
				}
			}
			
    stringBuffer.append(TEXT_16);
    stringBuffer.append(ModelerConstants.paletteFactory);
    stringBuffer.append(TEXT_17);
    stringBuffer.append(TEXT_18);
    return stringBuffer.toString();
  }
}
